const token = 'appToken';
const USER_KEY = 'userInfo';
// 控制 权限 token
export function setToken(valueToken: string) {
  localStorage.setItem(token, valueToken);
}
/**
 * 控制 权限 token
 * @returns
 */
export function getToken(): string {
  if (localStorage.getItem(token)) {
    return localStorage.getItem(token) + '';
  } else {
    return '';
  }
}
export function setUser(userInfo: { id: string | number; name: string }) {
  localStorage.setItem(USER_KEY, JSON.stringify(userInfo));
}
//
export function getUser(): { id?: string | number; name?: string } | null {
  const userStr = localStorage.getItem(USER_KEY);
  return userStr ? JSON.parse(userStr) : null;
}
export function removeToken() {
  localStorage.removeItem(token);
}

export function logout() {
  removeToken();
}
